package com.boot.provider;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.Getter;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.util.ObjectUtils;

public class MyWebAuthenticationDetails extends WebAuthenticationDetails {
    @Getter
    private boolean imageCodeIsRight;

//    public boolean isImageCodeIsRight() {
//        return imageCodeIsRight;
//    }
    public MyWebAuthenticationDetails(HttpServletRequest request) {
        super(request);
        String requestCode = request.getParameter("captcha");
        HttpSession session = request.getSession();
        String sessionCode = (String) session.getAttribute("captcha");
        if(!ObjectUtils.isEmpty(sessionCode)){
            session.removeAttribute("captcha");
            if(sessionCode.equals(requestCode)){
                this.imageCodeIsRight = true;
            }
        }
    }
}
